package me.yuzho.study.concurrency;

import java.util.stream.IntStream;

/**简单情况下，直接重写线程的run函数来执行任务
 * @author yzhou-citrix
 *
 */
public class SimpleThread extends Thread {
    
    private int countDown = 5;
    private static int threadCount = 0;
    
    public SimpleThread() {
        super("" + (++threadCount)); // name the thread
        start();
    }
    
    
    @Override
    public String toString() {
        
        return String.format("#%s (%d),", getName(), countDown);
    }

    @Override
    public void run() {
        while (true) {
            
            System.out.print(this);
            if(--countDown == 0)
                return;
            
        }
    }

    public static void main(String[] args) {
        IntStream.range(0, 5).forEach(i -> {
            
            new SimpleThread();
        });
    }

}
